﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ITAP.Core.Modelling.Primitives;
using System.Diagnostics;
using ITAP.ShprossesBuilder.Calculations;

namespace ITAP.ShprossesBuilder.Modelling.Components.Constraints
{
    [Serializable]
    public class ConnectedShprossesConnectorsEndToEndEndsJoin : IConstraint
    {
        #region IConstraint Members

        public bool Check(IComponent component)
        {
            return false;
        }

        public void Fix(IComponent component)
        {
            if (!(component is ShprossEndToEndConnector))
                return;
            ShprossEndToEndConnector endToEnd = component as ShprossEndToEndConnector;
            if (endToEnd.StartConnectedComponent == null || 
                !(endToEnd.StartConnectedComponent is ShprossEndToEndConnector))
                return;

            ShprossEndToEndConnector connectedEndToEnd = endToEnd.StartConnectedComponent as ShprossEndToEndConnector;
            connectedEndToEnd.MoveTo(endToEnd.StartPoint);
        }

        private bool enabled = true;
        public bool Enabled
        {
            get
            {
                return enabled;
            }
            set
            {
                enabled = value;
            }
        }

        public ConstraintAction Action
        {
            get { return ConstraintAction.Fix; }
        }

        #endregion

        #region ICloneable Members

        public object Clone()
        {
            ConnectedShprossesConnectorsEndToEndEndsJoin clone = new ConnectedShprossesConnectorsEndToEndEndsJoin();
            clone.Enabled = this.enabled;
            return clone;
        }

        #endregion
    }
}
